
// 添加用户
// chance_num,  抽奖机会
// user_nick， 
exports.addUser = async (params, cloud) => {
	try {
		let query = `insert into user (mix_nick, nick_name, openId) VALUES
	    ('${params.mixnick}','${params.nickName}','${params.openId}')`;
		let data = await cloudfn(cloud, query);
		return data;
	} catch (err) {
		return err;
	}
}

//查询用户
exports.getUser = async (mixnick, cloud) => {
	try {
		let query = `SELECT id as user_id FROM user WHERE mix_nick = '${mixnick}'`;
		let data = await cloudfn(cloud, query);
		return data;
	} catch (err) {
		return err;
	}
}


//加购
exports.addCart = async (params, cloud) => {
	try {
	let query = `insert into user_cart (mix_nick,nick_name, cart_data, sample_data,openId) VALUES
	    ('${params.mixnick}','${params.nickName}', '${params.cart_data}', '${params.sample_data}','${params.openId}')`;
		let data = await cloudfn(cloud, query);
		return data;
	} catch (err) {
		return err;
	}
}

exports.matchOrder= async (params, cloud) => {
	try {
	let query = `SELECT id as user_id FROM user_cart (mix_nick,nick_name, cart_data, sample_data) VALUES
	    ('${params.mixnick}','${params.nickName}', '${params.cart_data}', '${params.sample_data}')`;
		let data = await cloudfn(cloud, query);
		return data;
	} catch (err) {
		return err;
	}
}



// 埋点
exports.addUserStat = async (params, time, cloud) => {
	try {
		console.log("==============try==================")
		let query = `insert into tracking_message_record (data, gmt_create, gmt_modified) VALUES ('${params}', '${time}', now())`;
		let data = await cloudfn(cloud, query);
		return data;
	} catch (err) {
		console.log("==============err==================", err)
		return err;
	}
},

cloudfn = async (cloud, sql)=> {
	console.log("==============sql==================", sql)
	let cbData = await cloud.dataspace.executeSql(sql, [])
	console.log("==============cbData==================", cbData)
	return cbData
}




